package BinarySearch;

public class nextGreatestLetter {
    public char nextGreatestLetter(char[] letters, char target) {
        int l = 0;
        int h = letters.length - 1;
        while (l < h) {
            int middle = l + (h - l) / 2;
            if (letters[middle] > target) {
                h = middle;
            } else {
                l = middle + 1;
            }
        }
        if (letters[h] > target) {
            return letters[h];
        }
        return letters[0];
    }
}
